package com.crazyice.lee.reader;

import com.crazyice.lee.data.Score;
import com.crazyice.lee.data.Student;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.util.Random;

@Slf4j
public class ScoreList extends RichParallelSourceFunction<Score> {
    private boolean isRun=true;

    @Override
    public void run(SourceContext<Score> sourceContext) throws Exception {
        Random random=new Random();
        int number=0;
        while (isRun){
            number++;
            Score score=new Score();
            score.setStudentId(number);
            score.setScoreTotal(320+random.nextInt(250));
            sourceContext.collect(score);
            if (number>=12000)break;
        }

    }

    @Override
    public void cancel() {
        isRun=false;
    }
}
